package org.uni_hi.muus.util;

import java.util.Vector;

public class StringUtil {

	public static final char 
		CR='\r',
		LF='\n';
	public static final String 
		CRLF=CR+""+LF;
	
	public static String[] split(String str, String arg){
		Vector v=new Vector();
		String[] sa=null;
		int ni=0,oi=0;
		ni=str.indexOf(arg,ni);
		while(ni!=-1){
			v.addElement(str.substring(oi, ni));
			oi=ni;
			ni=str.indexOf(arg,ni);
		}
		v.addElement(str.substring(oi,str.length()));
		
		sa=new String[v.size()];
		v.copyInto(sa);
		return sa;
	}
	
	public static String replaceAll(String origin, String search, String replace){
		int i=origin.indexOf(search);
		if(i==-1)return origin;
		String first="",last=origin;
		while(i!=-1){
			first+=last.substring(0,i)+replace;
			last=last.substring(i+search.length());
			i=last.indexOf(search);
		}
		return first+last;
	}
	
	public static String replace(String origin, String search, String replace){
		int i=origin.indexOf(search);
		if(i==-1)return origin;
		String first=origin.substring(0,i), last=origin.substring(i+search.length());
		return first+replace+last;
	}
	
	public static String getHTMLDocforStatus(String status,String expl){
		return "<HTML><HEAD><TITLE>"+status+"</TITLE>"+
			"</HEAD><BODY>"+status+"<br/>"+expl+"</BODY></HTML>";
	}
}
